﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Comm100.Framework;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/agentAssist")]
    [ApiController]
    public class AgentAssistLearningQuestionsController : ControllerBase
    {

        private readonly IAgentAssistLearningQuestionAppService _app;
        public AgentAssistLearningQuestionsController(IAgentAssistLearningQuestionAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("learningQuestions/{id:Guid}")]
        public ActionResult<AgentAssistLearningQuestionDto> Get([FromRoute] Guid id)
        {
            AgentAssistLearningQuestionDto learningQuestion = _app.Get(id);
            return Ok(learningQuestion);
        }

        [HttpGet]
        [Route("learningQuestions")]
        public ActionResult<PagedListDto<AgentAssistLearningQuestionDto>> GetList([FromQuery]LearningQuestionQueryDto dto, [FromQuery]Paging paging)
        {
            PagedListDto<AgentAssistLearningQuestionDto> list = _app.GetList(dto, paging);
            return Ok(list);
        }

        [HttpDelete]
        [Route("learningQuestions/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }

        [HttpDelete]
        [Route("learningQuestions")]
        public ActionResult BatchDelete([FromBody] List<Guid> ids)
        {
            foreach (var id in ids)
            {
                _app.Delete(id);
            }
            return NoContent();
        }

        [HttpPost]
        [Route("learningQuestions")]
        public ActionResult<AgentAssistLearningQuestionDto> Post([FromBody] AgentAssistLearningQuestionCreateDto dto)
        {
            AgentAssistLearningQuestionDto learningQuestion = _app.Create(dto);
            return CreatedAtAction(nameof(Get), new { id = learningQuestion.Id }, learningQuestion);
        }

        [HttpPost]
        [Route("learningQuestions:batchCreate")]
        public ActionResult Post([FromBody] List<AgentAssistLearningQuestionCreateDto> dtos)
        {
            foreach (var dto in dtos)
            {
                _app.Create(dto);
            }
            return NoContent();
        }
    }
}
